package day16_Runnable.demo09例子;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;

//获取E:\csw\Demo\a\bigdata.txt文件里班级的数量
//以文科一班;50 为例输出
public class DemoClazzSum {
    public static void main(String[] args) throws Exception{
        HashMap<String, Integer> hashMap = new HashMap<>();
        BufferedReader br = new BufferedReader(new FileReader("E:\\csw\\Demo\\a\\bigdata.txt"));
        String line;
        while ((line=br.readLine())!=null){//读取所有数据到line中
            String s = line.split(",")[4];//切分字段获取班级
            if (hashMap.containsKey(s)){//判断班级是否在hashMap中
                hashMap.put(s,hashMap.get(s)+1);
            }else{
                hashMap.put(s,1);
            }
        }
        br.close();
        System.out.println(hashMap);
    }
}
